import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';

/**
 * 售后/退款单信息
 */
@Entity('order_refund')
export class OrderRefundEntity extends BaseEntity {
  @Column({ comment: '售后/退款单ID', nullable: false })
  id: number;

  @Column({ comment: '订单ID', nullable: false })
  orderId: number;

  @Column({ comment: '用户ID', nullable: true })
  userId: number;

  @Column({ comment: '商铺ID', nullable: false })
  shopId: number;

  @Index({ unique: true })
  @Column({ comment: '退款单号', nullable: true })
  refundNo: string;

  @Column({ comment: '总金额', type: 'decimal', precision: 10, scale: 2 })
  totalAmount: number;

  @Column({ comment: '退款金额', type: 'decimal', precision: 10, scale: 2 })
  refundAmount: number;

  @Column({
    comment: '退款状态',
    dict: ['待审核', '审核通过', '审核拒绝'],
    default: 0,
  })
  refundStatus: number;

  @Column({
    comment: '退款类型',
    dict: ['退货退款', '换货', '仅退款'],
  })
  refundType: number;

  @Column({ comment: '退款原因', length: 255, nullable: true })
  refundReason: string;

  @Column({ comment: '备注信息', type: 'text', nullable: true })
  reasonRemark: string;

  @Column({ comment: '申请时间', type: 'datetime', nullable: true })
  applyTime: Date;

  @Column({ comment: '审核时间', type: 'datetime', nullable: true })
  auditTime: Date;

  @Column({ comment: '完成时间', type: 'datetime', nullable: true })
  completeTime: Date;

  @Column({ comment: '审核人ID', nullable: true })
  auditorId: number;

  @Column({ comment: '审核人', length: 50, nullable: true })
  auditor: string;

  @Column({ comment: '审核备注', type: 'text', nullable: true })
  auditRemark: string;

  @Column({ comment: '售后/换货商品ID', nullable: false })
  goodIds: string;

  @Column({ comment: '退款凭证', type: 'json', nullable: true })
  proofImages: string[];

  @Column({
    comment: '退款商品详情',
    type: 'json',
    nullable: true
  })
  productDetails: Array<{
    id: number;
    name: string;
    price: number;
    quantity: number;
    reason: string;
  }>;

  @Column({ comment: '退款流水号', length: 50, nullable: true })
  transactionId: string;

  @Column({ comment: '物流单号', length: 50, nullable: true })
  logisticsNo: string;

  @Column({ comment: '物流公司', length: 50, nullable: true })
  logisticsCompany: string;

  // 镜片数量 （0为双眼，1为左眼，2为右眼）
  @Column({ comment: '镜片数量', nullable: true })
  lensQuantity: number;
}